package com.projectxxxxxxxxxx.ui;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.widget.TextView;

import com.projectxxxxxxxxxx.R;
import com.projectxxxxxxxxxx.info.Info;
import com.projectxxxxxxxxxx.service.GetInfoService;

public class DeviceActivity extends Activity {

	TextView cpuUsage;
	TextView cpuProcessor;
	TextView cpuCores;
	TextView memoryUsage;
	TextView baterryLavel;
	TextView storageInternalUsage;
	TextView storageExternalUsage;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.device_activity);

		cpuUsage = (TextView) findViewById(R.id.cpu_usage);
		cpuProcessor = (TextView) findViewById(R.id.cpu_processor);
		cpuCores = (TextView) findViewById(R.id.cpu_cores);
		memoryUsage = (TextView) findViewById(R.id.memory_usage);
		baterryLavel = (TextView) findViewById(R.id.baterry_lavel);
		storageInternalUsage = (TextView) findViewById(R.id.storage_internal_usage);
		storageExternalUsage = (TextView) findViewById(R.id.storage_external_usage);

		Intent intent = new Intent(this, GetInfoService.class);
		bindService(intent, serviceConnection, BIND_AUTO_CREATE);

	}
	
	private GetInfoService getInfoService;
	
	ServiceConnection serviceConnection = new ServiceConnection() {

		@Override
		public void onServiceDisconnected(ComponentName name) {
			getInfoService = null;
		}

		@Override
		public void onServiceConnected(ComponentName name, IBinder service) {
			getInfoService = ((GetInfoService.LocalBinder) service).getService();

			cpuUsage.setText(getInfoService.get(Info.CPU_USAGE, Info.INFO_CPU_USAGE));
			cpuProcessor.setText(getInfoService.get(Info.CPU_DATA, Info.INFO_CPU_PROCESSOR));
			cpuCores.setText(getInfoService.get(Info.CPU_DATA, Info.INFO_CPU_CORES));
			memoryUsage.setText(getInfoService.get(Info.MEMORY_USAGE, Info.INFO_MEMORY_USAGE));
			baterryLavel.setText(getInfoService.get(Info.BATTERY, Info.INFO_BATERRY_LAVEL));
			storageInternalUsage.setText(getInfoService.get(Info.STORAGE_INTERNAL_USAGE,
					Info.INFO_STORAGE_INTERNAL_USAGE));
			storageExternalUsage.setText(getInfoService.get(Info.STORAGE_EXTERNAL_USAGE,
					Info.INFO_STORAGE_EXTERNAL_USAGE));
		}
	};
}
